<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>main</title>
    <link rel="stylesheet" href="../public/css/admin/admin.css">

</head>
<body id="main">
<div class="map">
    文档管理 &gt;&gt; 查看文档 &gt;&gt; <span class="title">{$title}</span>
</div>

<ol class="subnav clear">
    <li class="selected"><a href="main_home_content.php?action=show">文档列表</a></li>
    <li><a href="main_home_content.php?action=add">新增文档</a></li>
    {if $update}
        <li><a href="main_home_content.php?action=update&id={$data->id}">修改文档</a></li>
    {/if}
</ol>

{if $add}
    <form action="main_home_content.php?action=add" method="post" name="content" class="content_add" >
        <table cellspacing="0" class="content">
            <tr>
                <th style="padding: 10px; background-color: #c8d1ff;"><strong>发布一条新文档</strong></th>
            </tr>
            <tr style="background: white">
                <td>　　</td>
            </tr>
            <tr>
                <td>
                    <label>
                        文档标题：
                        <input type="text" name="title" class="text"/><span class="red">&nbsp;必填&nbsp;</span>( * 标题字符2到25之间 )
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        栏　　目：
                        <select name="nav">
                            <option value="0">请选择一个分类</option>
                            {$all_navs}
                        </select> <span class="red">&nbsp;[必选]&nbsp;</span>
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    定义属性：
                    <label> <input type="checkbox" name="attr[]" value="头条"/>头条</label>
                    <label> <input type="checkbox" name="attr[]" value="推荐"/>推荐</label>
                    <label> <input type="checkbox" name="attr[]" value="加粗"/>加粗</label>
                    <label> <input type="checkbox" name="attr[]" value="跳转"/>跳转</label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        标　　签：
                        <input type="text" name="tag" class="text"/>
                        ( * 每个标签用','隔开，总长30位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <span style="letter-spacing: 4px;">关键字</span>：
                        <input type="text" name="keyword" class="text"/>
                        ( * 每个关键字用','隔开，总长30位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <span style="letter-spacing: 4px;">缩略图</span>：
                        <input type="text" name="thumbnail" readonly  class="text"/>
                        <input type="button" value="上传缩略图" style="padding: 2px  10px; margin-left: 10px;"
                               class="upload_file_btn"/>
                        ( * 必须是jpg,gif,png，并且200k内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <img style="margin-left: 64px;" src=""
                         id="thumbnailImg" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        文章来源：
                        <input type="text" name="source" class="text"/>
                        ( * 文章来源20位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        作　　者：
                        <input type="text" name="author" class="text"/>
                        ( * 作者10位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <span style="vertical-align: top;">内容摘要：</span>
                        <textarea name="info"></textarea>
                        <span style="vertical-align: top">( * 内容摘要200之内)</span>
                    </label>
                </td>
            </tr>
            <tr>
                <td id="ck_td">
                    <textarea name="content" id="editor"></textarea>
                    <script src="../public/js/ckeditor/ckeditor.js" type="text/javascript"></script>
                    <script>
                        CKEDITOR.replace('editor');
                    </script>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        评论选项：
                        <input type="radio" name="commend" value="1" checked="checked"/>
                    </label>

                    <label>
                        允许评论
                        <input type="radio" name="commend" value="0"/>禁止评论
                    </label>

                    <label>
                        &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;浏览次数：<input type="text" name="count" value="100"
                                                                   class="text small"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        文档排序：
                        <select name="sort">
                            {$sort_html}
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                    </label>

                    <label>
                        消费金币：
                        <input type="text" name="gold" value="0" class="text small"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    阅读权限：
                    <select name="readlimit">
                        {$limit_html}
                    </select>&nbsp;&nbsp;&nbsp;&nbsp;

                    标题颜色：
                    <select name="color">
                        <option value="">默认颜色</option>
                        <option value="red" style="color:red;">红色</option>
                        <option value="blue" style="color:blue;">蓝色</option>
                        <option value="orange" style="color:orange;">橙色</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" style="padding: 5px 10px;" value="发布文档"/>
                    <input type="reset" style="padding: 5px 10px;" style="" onclick="return confirm('确定重置吗？');" value="重置"/>
                </td>
            </tr>
        </table>
    </form>
{/if}

{if $delete}
    delete
{/if}

{if $update}
    <form action="main_home_content.php?action=update" method="post" name="content" class="content_add" >
        <input type="hidden" name="id" value="{$data->id}"  />
        <input type="hidden" name="prev_url" value="{#PREV_URL}" />
        <table cellspacing="0" class="content">
            <tr>
                <th style="padding: 10px; background-color: #c8d1ff;"><strong>发布一条新文档</strong></th>
            </tr>
            <tr style="background: white">
                <td>　　</td>
            </tr>
            <tr>
                <td>
                    <label>
                        文档标题：
                        <input type="text" name="title" class="text" value="{$data->title}" /><span class="red">&nbsp;必填&nbsp;</span>( * 标题字符2到25之间 )
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        栏　　目：
                        <select name="nav" class="nav">
                            <option value="0">请选择一个分类</option>
                            {$all_navs}
                        </select> <span class="red">&nbsp;[必选]&nbsp;</span>
                    </label>

                </td>
            </tr>
            <tr>
                <td class="attr">
                    定义属性：
                    <label> <input type="checkbox" name="attr[]" value="头条"/>头条</label>
                    <label> <input type="checkbox" name="attr[]" value="推荐"/>推荐</label>
                    <label> <input type="checkbox" name="attr[]" value="加粗"/>加粗</label>
                    <label> <input type="checkbox" name="attr[]" value="跳转"/>跳转</label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        标　　签：
                        <input type="text" name="tag" class="text" value="{$data->tag}"/>
                        ( * 每个标签用','隔开，总长30位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <span style="letter-spacing: 4px;">关键字</span>：
                        <input type="text" name="keyword" class="text" value="{$data->keyword}" />
                        ( * 每个关键字用','隔开，总长30位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <span style="letter-spacing: 4px;">缩略图</span>：
                        <input type="text" name="thumbnail" readonly class="text" value="{$data->thumbnail}"/>
                        <input type="button" value="上传缩略图" style="padding: 2px  10px; margin-left: 10px;"
                               class="upload_file_btn"/>
                        ( * 必须是jpg,gif,png，并且200k内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <img style="margin-left: 64px;" src="/{$data->thumbnail}"
                         id="thumbnailImg" width="200" height="150" />
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        文章来源：
                        <input type="text" name="source" class="text" value="{$data->source}" />
                        ( * 文章来源20位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        作　　者：
                        <input type="text" name="author" class="text" value="{$data->author}"/>
                        ( * 作者10位之内)
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        <span style="vertical-align: top;">内容摘要：</span>
                        <textarea name="info">{$data->info}</textarea>
                        <span style="vertical-align: top">( * 内容摘要200之内)</span>
                    </label>
                </td>
            </tr>
            <tr>
                <td id="ck_td">
                    <textarea name="content" id="editor">{$data->content}</textarea>
                    <script src="../public/js/ckeditor/ckeditor.js" type="text/javascript"></script>
                    <script>
                        CKEDITOR.replace('editor');
                    </script>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        评论选项：
                        <input type="radio" class="commend" name="commend" value="1" checked="checked"/>
                    </label>

                    <label>
                        允许评论
                        <input type="radio" class="commend" name="commend" value="0"/>禁止评论
                    </label>

                    <label>
                        &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;浏览次数：<input type="text" name="count" value="{$data->count}"
                                                                   class="text small"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    <label>
                        文档排序：
                        <select name="sort" class="sort">
                            {$sort_html}
                        </select>&nbsp;&nbsp;&nbsp;&nbsp;
                    </label>

                    <label>
                        消费金币：
                        <input type="text" name="gold" value="{$data->gold}" class="text small"/>
                    </label>
                </td>
            </tr>
            <tr>
                <td>
                    阅读权限：
                    <select name="readlimit" class="readlimit">
                        {$limit_html}
                    </select>&nbsp;&nbsp;&nbsp;&nbsp;

                    标题颜色：
                    <select name="color" class="color">
                        <option value="">默认颜色</option>
                        <option value="red" style="color:red;">红色</option>
                        <option value="blue" style="color:blue;">蓝色</option>
                        <option value="orange" style="color:orange;">橙色</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" style="padding: 5px 10px;" value="更新文档"/>
                    <input type="reset" style="padding: 5px 10px;" style="" onclick="return confirm('确定重置吗？');" value="重置"/>
                </td>
            </tr>
        </table>
    </form>
{/if}

{*显示文档列表*}
{if $show}
    <select class="nav" style="margin: 10px 37px;">
        <option value="0">请选择一个分类</option>
        {$all_navs}
    </select>  <button class="find">查找</button>
    <table class="list" border="0" cellpadding="0" cellspacing="0">
        <tr>
            <th width="10%">编号</th>
            <th >标题</th>
            <th width="10%">属性</th>
            <th width="10%">文档类别</th>
            <th width="10%">浏览次数</th>
            <th width="10%">发布时间</th>
            <th width="10%">操作</th>
        </tr>
        {if $AllList}
            {foreach $AllList(key,row)}
                <tr>
                    <!--<td>{@row->id}</td>-->
                    <td><script type="text/javascript">window.document.write( {@key+1} + {$page_base} );</script></td>
                    <td><a href="/detail.php?id={@row->id}" target="_blank">{@row->title}</a></td>
                    <td>{@row->attr}</td>
                    <td><a href="?action=show&nav_id={@row->nav_id}">{@row->nav_name} </a></td>
                    <td>{@row->count}</td>
                    <td>{@row->date}</td>
                    <td>
                        <a  href="main_home_content.php?action=update&id={@row->id}">修改</a> |
                        <a onclick="return confirm('确定删除该记录吗？');" href="main_home_content.php?action=delete&id={@row->id}">删除</a>
                    </td>
                </tr>
            {/foreach}
        {else}
            <tr><td colspan="8">对不起，没有找到任何数据</td></tr>
        {/if}
    </table>
    <!-- <p class="add_user">[ <a href="main_home_manage.php?action=add">新增管理员</a> ]</p> -->
    <p id="page"> {$page} </p>
{/if}

<script type="text/javascript" src="../public/js/jquery-1.10.2.js"></script>
<script type="text/javascript" src="../public/js/admin/admin.js"></script>
<script type="text/javascript">

    $(function () {
        $('.upload_file_btn').on('click', function () {
            openCenterWindow('upfile.html', '上传文件', 400, 100);
        });

        $('.find').on('click', function () {
            var nav_id = $('select.nav option:selected').val();
            window.location.href = '?action=show&nav_id='+nav_id;
            return false;
        });

    });

    {if $update}
        $(function () {
            $('select.nav option[value={$data->nav}]').attr('selected', true);

            var str = '{$data->attr}';
            if (str != ''){
                var arr = str.split(',');
                $('.attr input').each(function () {
                    var val = $(this).val();
                    if ($.inArray( val,  arr ) >= 0){
                        $(this).attr('checked', true);
                    }
                });
            }

            $('.commend[value={$data->commend}]').attr('selected',true);

            $('.color option').each(function () {
                console.log( $(this).val());
                if ( $(this).val() == '{$data->color}' ){
                    $(this).attr('selected', true);
                }
            });

            $('select.sort option[value={$data->sort}]').attr('selected',true);

            $('select.readlimit option[value={$data->readlimit}]').attr('selected',true);

        });
    {/if}

</script>
</body>
</html>